package com.controller;

import com.bean.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/page/login", method = RequestMethod.POST)
    public String login(HttpServletRequest request){
        HttpSession sessoin = request.getSession();
        String userPhone=request.getParameter("userPhone");
        String userPassword=request.getParameter("userPassword");
        User user=userService.login(userPhone,userPassword);
        if (user!=null){
            sessoin.setAttribute("username", userPhone);
            return "redirect:main.jsp";
        }
        else {
            request.setAttribute("msg", "密码不正确！");
            return "redirect:login.jsp";
        }
    }
}
